package io.xxx.xbutler.web.controller;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.xxx.xbutler.domain.Room;
import io.xxx.xbutler.domain.User;
import io.xxx.xbutler.service.RoomService;
import io.xxx.xbutler.web.controller.form.SetRobotAliasForm;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/room")
public class RoomController {

    @Resource
    private RoomService roomService;

    @GetMapping("/list")
    public Page<Room> list(Room room,
                           @RequestParam(defaultValue = "1") Integer pageNumber,
                           @RequestParam(defaultValue = "20") Integer pageSize) {
        log.debug("查询群列表[{}]", JSON.toJSONString(room));
        return roomService.list(room, pageNumber, pageSize);
    }

    @GetMapping("/get")
    public Room get(@RequestParam String id) {
        log.debug("查询群信息[{}]", id);
        return roomService.get(id);
    }

    @GetMapping("/export")
    public Long export(Room room, @RequestHeader User user) {
        log.debug("导出群列表[{}]", JSON.toJSONString(room));
        return roomService.export(room, user);
    }

    @PostMapping("/set_robot_alias")
    public String setAlias(@RequestBody SetRobotAliasForm form) {
        log.debug("修改群内机器人昵称[{}]", JSON.toJSONString(form));
        return roomService.setRobotAlias(form.getRoomId(), form.getRobotId(), form.getAlias());
    }
}
